#!/usr/bin/sh
echo "init frontpanel"
modprobe cn_micom paramDebug=0
modprobe simu_button

if [ -e /var/etc/.firstboot ]; then
   echo "WAIT 1 min"
   rm /var/etc/.firstboot
   touch /dev/.devfsd
fi

if [ -e /etc/init.d/mountvirtfs ]; then
   /etc/init.d/mountvirtfs start
fi
if [ -e /etc/init.d/portmap ]; then
   /etc/init.d/portmap start
fi

modprobe e2_proc

if [ -e /etc/init.d/autofs ]; then
   /etc/init.d/autofs start
fi

if [ ! -e /var/etc/.firstboot ]; then

   echo "Starting DEBUG Interface"
if [ -e /etc/init.d/mountall ]; then
   /etc/init.d/mountall start
fi

   echo "init stmfb"
   modprobe stmcore-display-sti7111
   modprobe stmfb display0=1280x720-32@50:15m:pal:yuv:yuv

   echo "LOADING MODULES"

   echo "load a firmware"
   /usr/bin/ustslave /dev/st231-1 /boot/audio.elf
   echo "load v firmware"
   /usr/bin/ustslave /dev/st231-0 /boot/video.elf

   echo "init embx"
   modprobe embxshell
   modprobe embxmailbox mailbox0=0xfe211000:136:set2 mailbox1=0xfe212000:0 ;
   modprobe embxshm mailbox0=shm:0:7:0x60000000:0:256:256:0:512:0x40000000:0x10000000 ;
   modprobe mme_host transport0=shm

   echo "init AVS"
   modprobe avs type=avs_none

   player=`cat /proc/stb/player/version | awk '{ print substr( $0, length($0) - 2, length($0) ) }'`
   echo "init player $player"

   modprobe mmelog
   modprobe ksound
   modprobe p2div64
   modprobe stm_v4l2
   if [ $player -gt 131 ]; then
	modprobe stmvout
	modprobe stmvbi
   fi
   modprobe pseudocard

   modprobe lnb type=pio
   modprobe stv090x paramDebug=0
   modprobe cnbox_cic
   if [ $player -gt 131 ]; then
	modprobe pti
	modprobe stm_monitor
	modprobe stmsysfs
    	modprobe stmdvb
   else
	modprobe pti
	modprobe stmdvb
	modprobe stm_monitor
   fi	
   modprobe player2
   modprobe sth264pp
   modprobe stmalloc
   modprobe platform
   modprobe silencegen
   modprobe smartcard

   modprobe bpamem
   mknod /dev/bpamem c 153 0 

   showiframe -p /usr/share/bootlogo.mvi &
   stfbcontrol a 0

   mknod /dev/rc c 147 1 
   mknod /dev/lnb c 149 0
   mknod /dev/sci0 c 169 0

   /usr/bin/evremote2 10 140 &

   stfbcontrol a 255

if [ -e /etc/init.d/mountall ]; then
   /etc/init.d/mountall start
fi
if [ -e /etc/init.d/vsftpd ]; then
   /etc/init.d/vsftpd start
fi
   /usr/sbin/inetd

   echo "LOADING E2"

   until false
   do
      echo "starting e2->"
      /usr/bin/enigma2
      rtv=$?
      echo "e2 ended <- RTV: " $rtv
      case "$rtv" in
		0) echo "0"
		   echo "E2 ERROR"
      	   init 6;;
		1) echo "1"
		   echo "SHUTDOWN"
		   init 0;;
		2) echo "2"
		   echo "REBOOT"
		   init 6;;
		3) echo "3"
		   echo "E2 RESTART"
		   echo "0" > /proc/progress
		   showiframe -p /usr/share/bootlogo.mvi &;;
		*) echo "*"
		   echo "ERROR"
           init 6;;
      esac
   done 
fi
